package per.ethan.cloud.consumer.controller;

import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import per.ethan.cloud.common.domain.ResultBean;
import per.ethan.cloud.provider.api.RemotePaymentService;
import per.ethan.cloud.provider.api.entity.Payment;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Ethan
 * @date 2020/03/12 19:35
 */
@Slf4j
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class OrderController {

    private final RemotePaymentService paymentService;

    private final HttpServletRequest request;

    @PostMapping
    public ResultBean<Long> save(@RequestBody Payment payment) {
        return paymentService.save(payment);
    }

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "通过ID查询支付信息")
    public ResultBean<Payment> getById(@PathVariable("id") Long id) {
        log.info("token: {}", request.getHeader("token"));
        return paymentService.getById(id);
    }

    @GetMapping(value = "/feignTimeout")
    @ApiOperation(value = "连接超时测试接口")
    public ResultBean<String> feignTimeout() {
        return paymentService.feignTimeout();
    }

    @GetMapping(value = "/hello")
    @ApiOperation(value = "hello")
    public ResultBean<String> hello() {
        return paymentService.hello();
    }

}
